<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
class User extends Model implements AuthenticatableContract
{
    use SoftDeletes,Authenticatable;
    protected $table='users';
    
    protected $primaryKey = 'id';
    
    protected $fillable = ['login_name', 'password','qw_userid','group_id', 'corpid','is-leader','role_id'];

    protected $dates = ['deleted_at'];


    public function getRole(){
        $role=( DB::table("role_user")->select("role_id")->where("user_id",$this->id)->first() );
        if(is_null($role)){

            $role=0;
        }else{
            $role= $role->role_id;
        }
        return $role;
    }

    public function achievement(){
        return $this->hasMany('App\Models\Achievement');

    }
}